package com.by.controller;

import cn.hutool.core.bean.BeanUtil;
import com.by.bean.Forwarder;
import com.by.common.bean.PageBean;
import com.by.common.bean.ResultBean;
import com.by.common.controller.BaseController;
import com.by.common.group.V;
import com.by.query.ForwarderQuery;
import com.by.service.impl.ForwarderService;
import com.by.service.impl.impl.ForwarderServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "货代端")
@RequestMapping("/api")
public class ForwarderController extends BaseController {

    @Autowired
    ForwarderService forwarderService;
    @Autowired
    ForwarderServiceImpl forwarderServiceImpl;

    @PostMapping("/forwarder")
    @ApiOperation("保存货代信息")
    public ResultBean save( @RequestBody Forwarder forwarder) {
        int rs = forwarderService.save(forwarder);
        return saveResult(rs);
    }

    @ApiOperation("删除货代信息")
    @DeleteMapping("/forwarder/{id}")
    public ResultBean delete(@PathVariable Integer id) {
        int rs = forwarderService.delete(id);
        return deleteResult(rs);

    }
    @ApiOperation("修改货代信息")
    @PutMapping("/forwarder/update")
    public ResultBean update(@RequestBody Forwarder forwarder){
        int rs = forwarderService.update(forwarder);
        return updateResult(rs);
    }

    @ApiOperation("查询货代信息")
    @GetMapping("/forwarder/get/{id}")
    public ResultBean get(@PathVariable Integer id) {
        Forwarder forwarder = forwarderServiceImpl.get(id);
        return success("获取成功", forwarder);
    }

    @ApiOperation("分页查询货代信息")
    @PostMapping("/forwarder/list")
    public ResultBean<PageBean<List<Forwarder>>> query(@RequestBody ForwarderQuery forwarder) {
        PageBean bean = forwarderService.queryByMap(BeanUtil.beanToMap(forwarder));
        return success("货代列表", bean);

    }

}
